<?php
namespace app\store\controller\shanghui;
use app\store\controller\Controller;
use app\store\model\Team as TeamModel;
use app\store\model\team\Category as CategoryModel;
use app\store\model\Shanghui;
use think\Db;

/**
 * 商会管理控制器
 * Class Examine
 * @package app\store\controller\content
 */
class Examine extends Controller
{
    /**
     * 待审核商会列表
     * @return mixed
     * @throws \think\exception\DbException
     */
    public function index()
    {
        $model = new Shanghui;
        $list = $model->getList();
        //  var_dump($list[0]['logoImage']);die;
        return $this->fetch('index', compact('list'));
    }

    /**
     * 待审核商会列表
     * @return mixed
     * @throws \think\exception\DbException
     */
    public function list()
    {
        $model = new Shanghui;
        $list = $model->getList(90);
        // var_dump( $list);die;
        return $this->fetch('list', compact('list'));
    }
    /**
     * 通过审核
     * @param $article_id
     * @return array|mixed
     * @throws \think\exception\DbException
     */
    public function edit($shanghui_id)
    { 
        $info = Db::name('shanghui')->where("id",$shanghui_id)->find();
        if($info){
            Db::startTrans();
            try {
                // 商会表更新状态
                Db::name('shanghui')->where("id",$shanghui_id)->update(['status' => 90]);
                //shanghui_user中间表插入数据
                $indata = [
                        'user_id'=>$info["userid"],
                        'shanghui_id'=>$shanghui_id,
                        'status' =>90,
                        'identity'=>$info["identity"],
                        'add_date'=>$info["add_date"],
                        'update_time'=>date('Y-m-d H:i:s'),
                        'grade_id'=>10009,
                        'examine_role'=>1
                ];
                Db::name('shanghui_user')->insert($indata);
                Db::name('user')->where("user_id",$info["userid"])->update(['shanghui_id'=>$shanghui_id,'grade_id'=>10009,'examine_role'=>1]);
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return $this->renderError($e->getMessage() ?: '操作失败');
            }
            return $this->renderSuccess('操作成功');
        }
    }

    /**
     * 删除文章
     * @param $article_id
     * @return array
     * @throws \think\exception\DbException
     */
    public function delete($shanghui_id)
    {
        Db::name('shanghui')->where("id",$shanghui_id)->delete();
        return $this->renderSuccess('删除成功');
    }

}